-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process: make process.nextTick()
awaitable
#38393
base: main
Are you sure you want to change the base?
Conversation
lib/internal/process/task_queues.js
Outdated
let promise; | ||
|
||
if (!arguments.length) { | ||
const defered = createDeferredPromise(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const defered = createDeferredPromise(); | |
const deferred = createDeferredPromise(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/internal/process/task_queues.js
Outdated
const defered = createDeferredPromise(); | ||
promise = defered.promise; | ||
const { resolve } = defered; | ||
callback = nextTickDefaultCallback.bind(undefined, resolve); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be simplified without the destructuring assignment above this line along with:
callback = nextTickDefaultCallback.bind(undefined, resolve); | |
callback = nextTickDefaultCallback.bind(undefined, deferred.resolve); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should exist, it's basically "run at the end of the microtask queue after the next tick", which is not an idiom anyone should be reaching for.
It just for So: const deferred = createDeferredPromise();
setTimeout(() => { derferred.resolve; }, 0);
await deferred.promise;
// .. do something in next (or next next ...) tick may be OK too. |
What use case would be solved by this that cannot work with import { setImmediate } from 'timers/promises';
await setImmediate() |
I mean just like |
This is similar to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also -1, if you want a version of proces.nextTick
that returns a Promise you can just await null
or await Promise.resolve()
.
If anything ideally we'll deprecate process.nextTick
in favour of the web standard queueMicrotask
Note that
Their naming is pretty confusing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm generally -1 on this. There are already a number of ways of doing similar deferals...
await Promise.resolve();
// or
await new Promise((resolve) => process.nextTick(resolve));
// or, with slightly different timing semantics...
const { setTimeout } = require('timers/promises');
await setTimeout();
Let's leave process.nextTick()
unchanged. We don't need Promise APIs for everything.
Yep. Making nextTick awaitable just makes things even weirder. |
I am -1 as well..I think this would just make things even more complex for our users, with no obvious gains |
As just an opinion from userland, a general -1 to bloating up and adding unnecessary complexity for minimal gain and usage. In terms of performance, this PR introduces additional quaint checks that hog the EL and you can always use any of the aforementioned solutions for some specialised use cases. Copying in @tbnritzdoge as well who is also familiar with async overhead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removal of all edits here
For code changes:
make -j4 test
(UNIX), orvcbuild test
(Windows) passes.